//
//  MyHeaderView.swift
//  UNHimalayas
//
//  Created by 王水平 on 2019/11/21.
//  Copyright © 2019 HachiTech. All rights reserved.
//

import UIKit

class MyHeaderView: UIView {

    var myImgView : UIImageView!
    var loginBtn : UIButton!
    var loginLabel : UILabel!
    var vipView : UIView!
    var vipContentLabel : UILabel!
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        initMyImageView()
        initLoginButton()
        initLoginLabel()
        initVipView()
        initVipImageView()
        initVipTitleLabel()
        initVipContentLabel()
        initVipArrowsImageView()
    }
    
    func initMyImageView() -> Void {
        
        myImgView = UIImageView()
        myImgView.backgroundColor = .clear
        myImgView.image = UIImage(named: "host_ic_avatar_default")
        myImgView.layer.cornerRadius = kRealWidth(35)
        myImgView.layer.masksToBounds = true
        self.addSubview(myImgView)
        
        myImgView.snp.makeConstraints { (make) in
            
            make.top.equalToSuperview().offset(kRealWidth(15))
            make.left.equalToSuperview().offset(kRealWidth(15))
            make.width.height.equalTo(kRealWidth(70))
        }
    }
    
    func initLoginButton() -> Void {
        
        loginBtn = UIButton()
        loginBtn.backgroundColor = UIColor.clear
        loginBtn.setTitle("立即登录", for: .normal)
        loginBtn.titleLabel?.font = UIFont.boldSystemFont(ofSize: kRealFont(14))
        loginBtn.setTitleColor(RGBA(248, g: 82, b: 14, a: 1.0), for: .normal)
        loginBtn.layer.cornerRadius = kRealWidth(15)
        loginBtn.layer.masksToBounds = true
        loginBtn.layer.borderWidth = 1
        loginBtn.layer.borderColor = RGBA(248, g: 82, b: 14, a: 1.0).cgColor
        loginBtn.addTarget(self, action: #selector(clickedBtn(btn:)), for: .touchUpInside)
        self.addSubview(loginBtn)
        
        loginBtn.snp.makeConstraints { (make) in
            
            make.top.equalTo(myImgView).offset(kRealWidth(10))
            make.left.equalTo(myImgView.snp.right).offset(kRealWidth(15))
            make.width.equalTo(kRealWidth(80));
            make.height.equalTo(kRealWidth(30));
        }
    }
    
    func initLoginLabel() -> Void {
        
        loginLabel = UILabel()
        loginLabel.backgroundColor = UIColor.clear
        loginLabel.text = "登录后，自动同步所有记录哦~"
        loginLabel.textColor = RGBA(105, g: 105, b: 105, a: 1.0)
        loginLabel.textAlignment = .left
        loginLabel.font = UIFont.systemFont(ofSize: kRealFont(13))
        self.addSubview(loginLabel)
        
        loginLabel.snp.makeConstraints { (make) in
            
            make.top.equalTo(loginBtn.snp.bottom).offset(kRealWidth(8))
            make.left.equalTo(myImgView.snp.right).offset(kRealWidth(15))
            make.right.equalToSuperview();
            make.height.equalTo(kRealWidth(13));
        }
    }
    
    func initVipView() -> Void {
        
        vipView = UIView()
        vipView.backgroundColor = RGBA(251, g: 244, b: 241, a: 1.0)
        vipView.layer.cornerRadius = kRealWidth(8)
        vipView.layer.masksToBounds = true
        self.addSubview(vipView)
        
        vipView.snp.makeConstraints { (make) in
            
            make.top.equalTo(myImgView.snp.bottom).offset(kRealWidth(16))
            make.left.equalToSuperview().offset(kRealWidth(15))
            make.right.equalToSuperview().offset((kRealWidth(-15)))
            make.height.equalTo(kRealWidth(45))
            make.bottom.equalToSuperview()
        }
    }
    
    func initVipImageView() -> Void {
        
        let imgView = UIImageView()
        imgView.backgroundColor = .clear
        imgView.image = UIImage(named: "vip_channel_ic")
        self.vipView.addSubview(imgView)
        
        imgView.snp.makeConstraints { (make) in
            
            make.centerY.equalToSuperview()
            make.leading.equalToSuperview().offset(kRealWidth(15))
            make.size.equalTo(CGSize(width: 17,height: 19))
        }
    }
    
    func initVipTitleLabel() -> Void {
        
        let label = UILabel()
        label.backgroundColor = UIColor.clear
        label.text = "VIP会员"
        label.textColor = RGBA(149, g: 116, b: 101, a: 1.0)
        label.textAlignment = .left
        label.font = UIFont.systemFont(ofSize: 14)
        self.vipView.addSubview(label)
        
        label.snp.makeConstraints { (make) in
            
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(kRealWidth(43))
            make.height.equalTo(kRealWidth(14))
            make.width.equalTo(kRealWidth(100))
        }
    }
    
    func initVipContentLabel() -> Void {
        
        vipContentLabel = UILabel()
        vipContentLabel.backgroundColor = UIColor.clear
        vipContentLabel.text = "VIP限时特惠"
        vipContentLabel.textColor = RGBA(149, g: 116, b: 101, a: 1.0)
        vipContentLabel.textAlignment = .right
        vipContentLabel.font = UIFont.systemFont(ofSize: 14)
        self.vipView.addSubview(vipContentLabel)
        
        vipContentLabel.snp.makeConstraints { (make) in
            
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(kRealWidth(-32))
            make.height.equalTo(kRealWidth(14))
            make.width.equalTo(kRealWidth(100))
        }
    }
    
    func initVipArrowsImageView() -> Void {
        
        let imgView = UIImageView()
        imgView.backgroundColor = .clear
        imgView.image = UIImage(named: "icon／next_58C89562F58FD276F592420068DB8C09_0")
        self.vipView.addSubview(imgView)
        
        imgView.snp.makeConstraints { (make) in
            
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(kRealWidth(-15))
            make.width.equalTo(kRealWidth(5))
            make.height.equalTo(kRealWidth(8))
        }
    }
    
    @objc func clickedBtn(btn : UIButton) -> Void {
        
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
